1
|
|
|
define(['sorttable', 'snabbdom', 'helper'], function (SortTable, V, helper) { |
2
|
|
|
'use strict'; |
3
|
|
|
V = V.default; |
4
|
|
|
|
5
|
|
|
function linkName(d) { |
6
|
|
|
return (d.source ? d.source.hostname : d.source.id) + ' – ' + d.target.hostname; |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
var headings = [{ |
10
|
|
|
name: '', |
11
|
|
|
sort: function (a, b) { |
12
|
|
|
return a.type.localeCompare(b.type); |
13
|
|
|
} |
14
|
|
|
}, { |
15
|
|
|
name: 'node.nodes', |
16
|
|
|
sort: function (a, b) { |
17
|
|
|
return linkName(a).localeCompare(linkName(b)); |
18
|
|
|
}, |
19
|
|
|
reverse: false |
20
|
|
|
}, { |
21
|
|
|
name: 'node.tq', |
22
|
|
|
class: 'ion-connection-bars', |
23
|
|
|
sort: function (a, b) { |
24
|
|
|
return (a.source_tq + a.target_tq) / 2 - (b.source_tq + b.target_tq) / 2; |
25
|
|
|
}, |
26
|
|
|
reverse: true |
27
|
|
|
}, { |
28
|
|
|
name: 'node.distance', |
29
|
|
|
class: 'ion-arrow-resize', |
30
|
|
|
sort: function (a, b) { |
31
|
|
|
return (a.distance === undefined ? -1 : a.distance) - |
32
|
|
|
(b.distance === undefined ? -1 : b.distance); |
33
|
|
|
}, |
34
|
|
|
reverse: true |
35
|
|
|
}]; |
36
|
|
|
|
37
|
|
|
return function (linkScale) { |
38
|
|
|
var table = new SortTable(headings, 3, renderRow); |
39
|
|
|
|
40
|
|
|
function renderRow(d) { |
41
|
|
|
var td1Content = [V.h('a', { |
42
|
|
|
props: { |
43
|
|
|
href: router.generateLink({ link: d.id }) |
44
|
|
|
}, on: { |
45
|
|
|
click: function (e) { |
46
|
|
|
router.fullUrl({ link: d.id }, e); |
47
|
|
|
} |
48
|
|
|
} |
49
|
|
|
}, linkName(d))]; |
50
|
|
|
|
51
|
|
|
return V.h('tr', [ |
52
|
|
|
V.h('td', V.h('span', { props: { className: 'icon ion-' + (d.type.indexOf('wifi') === 0 ? 'wifi' : 'share-alt'), title: _.t(d.type) } })), |
53
|
|
|
V.h('td', td1Content), |
54
|
|
|
V.h('td', { style: { color: linkScale((d.source_tq + d.target_tq) / 2) } }, helper.showTq(d.source_tq) + ' - ' + helper.showTq(d.target_tq)), |
55
|
|
|
V.h('td', helper.showDistance(d)) |
56
|
|
|
]); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
this.render = function render(d) { |
60
|
|
|
var h2 = document.createElement('h2'); |
61
|
|
|
h2.textContent = _.t('node.links'); |
62
|
|
|
d.appendChild(h2); |
63
|
|
|
table.el.elm.classList.add('link-list'); |
64
|
|
|
d.appendChild(table.el.elm); |
65
|
|
|
}; |
66
|
|
|
|
67
|
|
|
this.setData = function setData(d) { |
68
|
|
|
table.setData(d.links); |
69
|
|
|
}; |
70
|
|
|
}; |
71
|
|
|
}); |
72
|
|
|
|